// f[i][j]表示从1到[i,j]的路径的最大值
// 由于路径长度有负数，所以需要先预处理成无穷小
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 510, INF = -1e9;
int dp[N][N];
int n;

int main()
{
    cin >> n;
    // 初始化动态规划数组
    // 为了省去判断边界情况，需要将边界也初始化成无穷小
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j <= i + 1; ++j)
            dp[i][j] = INF;

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= i; ++j)
            cin >> dp[i][j];
    for (int i = 2; i <= n; ++i)
        for (int j = 1; j <= i; ++j)
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + dp[i][j];

    int res = INF;
    for (int i = 1; i <= n; ++i)
        res = max(dp[n][i], res);
    cout << res << endl;
    return 0;
}